/*complex.hpp
#ifndef COMPLEX_H
#define COMPLEX_H

class Complex
{
private:
    double real, image; // 复数的实部与虚部
public:
    Complex(double r = 0, double i = 0); // 构造函数
    Complex(const Complex &other);       // 拷贝构造函数
    void print();                        // 打印复数

    Complex operator+(const Complex &other); // 重载加法运算符（二元）
    Complex operator-(const Complex &other); // 重载减法运算符（二元）
    Complex operator-();                     // 重载求负运算符（一元）
    Complex operator=(const Complex &other); // 重载赋值运算符（二元）

    Complex &operator++();   // 重载前置++
    Complex operator++(int); // 重载后置++
    Complex &operator--();   // 重载前置--
    Complex operator--(int); // 重载后置--
};
#endif
*/

#include <iostream>

// #include "complex.hpp"
class Complex {
   private:
    double real, image;  // 复数的实部与虚部
   public:
    Complex(double r = 0, double i = 0);  // 构造函数
    Complex(const Complex &other);        // 拷贝构造函数
    void print();                         // 打印复数

    Complex operator+(const Complex &other);  // 重载加法运算符（二元）
    Complex operator-(const Complex &other);  // 重载减法运算符（二元）
    Complex operator-();                      // 重载求负运算符（一元）
    Complex operator=(const Complex &other);  // 重载赋值运算符（二元）

    Complex &operator++();    // 重载前置++
    Complex operator++(int);  // 重载后置++
    Complex &operator--();    // 重载前置--
    Complex operator--(int);  // 重载后置--
};

using namespace std;

// Complex::Complex(double r,double)
// Complex::Complex(double r) : real(r), image(0) {}
Complex::Complex(double r, double i) { real = r, image = i; }
Complex::Complex(const Complex &other) : real(other.real), image(other.image) {}
Complex Complex::operator+(const Complex &other) { return Complex(real + other.real, image + other.image); }
Complex Complex::operator-(const Complex &other) { return Complex(real - other.real, image - other.image); }
Complex Complex::operator-() { return Complex(-real, -image); }
Complex Complex::operator=(const Complex &other) {
    real = other.real;
    image = other.image;
    return *this;
}
Complex &Complex::operator++() {
    real++;
    image++;
    return *this;
}
Complex Complex::operator++(int) {
    Complex temp = *this;
    real++;
    image++;
    return temp;
}
Complex &Complex::operator--() {
    real--;
    image--;
    return *this;
}
Complex Complex::operator--(int) {
    Complex temp = *this;
    real--;
    image--;
    return temp;
}
void Complex::print() {
    cout << real;
    if (image > 0)
        cout << "+" << image << "i";
    else if (image < 0)
        cout << image << "i";
    cout << endl;
}

int main() {
    Complex c1(1, 2);  // 定义一个值为1 + 2i的复数c1
    Complex c2(2);     // 定义一个值为2的复数c2
    Complex c3(c1);    // 用拷贝构造函数创建一个值同c1的新复数

    c3.print();         // 打印c3的值
    c1 = c1 + c2 + c3;  // 将c1加上c2再加上c3赋值给c1
    c2 = -c3;           // c2等于c3求负
    c3 = c2 - c1;       // c3等于c2减去c1
    c3.print();         // 再打印运算后c3的值

    Complex temp = c3++;
    temp.print();
    c3.print();

    temp = c3--;
    temp.print();
    c3.print();

    temp = --c3;
    temp.print();
    c3.print();

    temp = ++c3;
    temp.print();
    c3.print();

    return 0;
}